package com.hyt.it.ogt.kq.main.controller.bm;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.it.ogt.kq.common.bm.utils.Constant;
import com.hyt.it.ogt.kq.common.utils.KqStringUtils;
import com.hyt.it.ogt.kq.service.bm.model.entity.InvoiceResult;
import com.hyt.it.ogt.kq.service.bm.model.vo.InvoiceResultVo;
import com.hyt.it.ogt.kq.service.bm.service.IInvoiceResultService;
import com.hyt.log.annotation.Log;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;

/**
 * <p>
 * 发票回调信息 前端控制器
 * </p>
 *
 * @author liteng
 * @since 2020-09-01
 */
@RestController
@Api(tags = "17.发票详情", value = "发票详情")
@ApiSort(value = 17)
@RequestMapping("/bm/invoice-result")
public class InvoiceResultController {

    @Autowired
    IInvoiceResultService iInvoiceResultService;

    @ApiOperation(value = "17.1.1 保存发票结果", notes = "14001:成功；14019：保存失败")
    @ApiOperationSort(value = 1)
    @Log(module = "发票详情管理", business = "保存发票结果")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Object save(@RequestBody InvoiceResult invoiceResult) {
        boolean bool = true;
        if (KqStringUtils.isBlank(invoiceResult.getId())) {

            bool  =  iInvoiceResultService.save(invoiceResult);
        } else {
            bool  =  iInvoiceResultService.saveOrUpdate(invoiceResult);
        }
        if (bool) {
            return ApiResponse.builder()
                    .code(Constant.RESPONSE_CODE_SUCCESS)
                    .data(invoiceResult)
                    .build();
        } else {
            return ApiResponse.builder()
                    .code(Constant.RESPONSE_CODE_31010116)
                    .data(invoiceResult)
                    .build();
        }
    }

    @ApiOperation(value = "17.1.2 查看项目数据", notes = "14001:成功；14020：未查找到项目数据")
    @ApiOperationSort(value = 2)
    @RequestMapping(value = "/query/{id}", method = RequestMethod.GET)
    public Object query(@PathVariable String id) {
        InvoiceResult invoiceResult = iInvoiceResultService.getById(id);
        if (invoiceResult != null) {
            return ApiResponse.builder()
                    .code(Constant.RESPONSE_CODE_SUCCESS)
                    .data(invoiceResult)
                    .build();
        } else {
            return ApiResponse.builder()
                    .code(Constant.RESPONSE_CODE_31010117)
                    .data(invoiceResult)
                    .build();
        }
    }

    @ApiOperation(value = "17.1.3 查询开票详情", notes = "14001:成功；14020：未查找到开票详情", response = InvoiceResultVo.class)
    @ApiOperationSort(value = 3)
    @RequestMapping(value = "/queryInvoiceResult", method = RequestMethod.GET)
    public Object queryInvoiceResult(String invoiceId){
        InvoiceResultVo vo = iInvoiceResultService.queryInvoiceResult(invoiceId);
        return ApiResponse.builder()
                .code(Constant.RESPONSE_CODE_SUCCESS)
                .data(vo)
                .build();
    }
}
